package com.hempton.flexmarkers;

import java.util.Map;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;

/**
 * Builder which removes flex markers from the
 * associated project. This is intended to be be
 * configured to take place right before the Ant Builder
 * is run
 * @author ghempton
 *
 */
public class FlexMarkerCleaner extends IncrementalProjectBuilder {

	public static final String BUILDER_ID = "com.hempton.flexmarkers.flexMarkerCleaner";

	private FlexMarkerManager markerManager;
	
	@Override
	protected void startupOnInitialize() {
		markerManager = new FlexMarkerManager();
	}
	
	@SuppressWarnings("unchecked")
	@Override
	protected IProject[] build(int kind, Map args, IProgressMonitor monitor)
			throws CoreException {
		/*
		 * We ignore automatic builds to parallel the
		 * ant builder behavior
		 */
		if(kind!=AUTO_BUILD) {
			removeMarkers();
		}
		return null;
	}
	
	protected void removeMarkers() {
		
		markerManager.removeMarkers(getProject());

	}
}
